package com.webinsky.web.utils;

import java.util.Calendar;

import org.springframework.web.server.WebSession;

import com.webinsky.domain.user.Account;


public class WebSessionUtils {
	/**
	 * 上传user信息
	 * @param session
	 * @param user
	 */
	public static void putAccount(WebSession session, Account account){
		session.getAttributes().put("user", account);
	}
	/**
	 * 取得user信息
	 * @param session
	 * @return
	 */
	public static Account getAccount(WebSession session){
		return session.getAttribute("user");
	}
	
	/**
	 * @param session
	 * @return
	 */
	public static boolean adminIsLogin(WebSession session){
		boolean isLogin = session.getAttribute("admin_login");
		return isLogin;
	}
	
	/**
	 * @param session
	 * @param isLogin
	 */
	public static void setAdminIsLogin(WebSession session, Boolean isLogin){
		session.getAttributes().put("admin_login", isLogin);
	}
	
	/**
	 * @param session
	 * @return
	 */
	public static String getVerfycode(WebSession session){
		return session.getAttribute("code");
	}
	
	/**
	 * @param session
	 * @param code
	 */
	public static void setVerfycode(WebSession session, String code){
		session.getAttributes().put("code", code);
	}
	
	/**
	 * @param session
	 */
	public static void setCodeExpireTime(WebSession session){
		Calendar c = Calendar.getInstance();
		c.add(Calendar.MINUTE, 10);
		session.getAttributes().put("expire_time", c.getTimeInMillis());
	}
	
	/**
	 * @param session
	 * @return
	 */
	public static Long getCodeExpireTime(WebSession session){
		return session.getAttribute("expire_time");
	}
}
